A representation of the genetic code as a six-dimensional Boolean hypercube is described. This structure is the result of the hierarchical order of the interaction energies of the bases in codon-anticodon recognition. In this paper it is applied to study molecular evolution in vivo and in vitro. In the first case we compared aligned positions in homologous protein sequences and found two different behaviors: a) There are sites in which the different amino acids may be explained by one or two "attractor nodes" (coding for the dominating amino acid(s)) and their one-bit neighbors in the codon hypercube, and b) There are sites in which the amino acids correspond to codons located in closed paths in the hypercube. In the second case we studied the "Sexual PCR" experiment described by Stemmer and found that the success of this combination of usual PCR and recombination is in part due to the Gray code structure of the genetic code.